<html>
  <head>
    <%#=wicked_pdf_stylesheet_link_tag 'admin/invoice' %>
  </head>
  <body>
    <div class="head">
      <div class="logo">
        <%#= wicked_pdf_image_tag "logo.png"%>
      </div>
      <div class="head-info">
        <ul>
          <li>Geekcups srls - P.Iva - C.F. - Registro imprese: xxx REA: PD-41132</li>
          <li><strong>Sede legale</strong>: via xxx</li>
          <li><strong>Sede operativa</strong>: via Croce Rossa 36, Padova (PD), 35129</li>
          <li>info@geekcups.com - Capitale sociale: € 900</li>
        </ul>
      </div>
    </div>
    
    <div class="customer-head">
      <div class="customer-info">
        <ul>
          <li>Spett.le </li>
          <li><%= "#{@order.bill_address.firstname} #{@order.bill_address.lastname}"%> </li>
          <li><%= "#{@order.bill_address.address1}"%> </li>
          <li><%= "#{@order.bill_address.zipcode} #{@order.bill_address.city} (#{@order.bill_address.state_name.nil? ? @order.bill_address.state.name : @order.bill_address.state_name})"%></li>
          <li>P.Iva e Cod. Fisc. IT 02259591200 </li>
        </ul>
      </div>
      <div class="head-invoice-info">
        <ul>
          <li><%= t('invoice.document')%>: <strong><%= t('invoice.bill_of_sale')%></strong></li>
          <li><%= t('invoice.date') %>: <strong><%= @order.invoice.created_at %></strong></li>
          <li><%= t('invoice.number') %>: <strong><%= @order.invoice.number %></strong></li>
        </ul>
      </div>
    </div>
    
    <table>
      <tr>
        <th><%= t('invoice.description')%></th>
        <th><%= t('invoice.quantity')%></th>
        <th><%= t('invoice.unit_amount')%></th>
        <% @order.taxes.each do |tax| %>
          <th><%= tax[:tax_rate].name%></th>
        <% end%>
        <th><%= t('invoice.total')%></th>
      </tr>
      
      <% @order.line_items.each do |line_item| %>
        <tr>
          <td><%= line_item.product.description %></td>
          <td><%= line_item.quantity %></td>
          <td><%= number_to_currency line_item.price_untaxed %></td>
          <% @order.taxes.each do |tax| %>
            <% i = line_item.taxes.index { |r| r[:tax_rate] == tax[:tax_rate] }%>
            <% if i %>
              <td><%= number_to_percentage line_item.taxes[i][:tax_rate].amount * 100 %></td>
            <% else %>
              <td>&nbsp;</td>
            <% end %>
          <% end%>
          <td><%= line_item.total_taxed %></td>
        </tr>
        <% if line_item.respond_to? :discount and line_item.discount > 0 %>
          <tr>
            <td>(<%= t('invoice.discount') %>)</td>
            <td>-<%= line_item.single_money %></td>
            <td>&nbsp;</td>
            <td>-<%= number_to_currency line_item.display_amount %></td>
          </tr>
        <% end %>
      <% end %>
    </table>
    
    <table>
      <tr>
        <td><%= t(:item_total) %>: </td>
        <td><%= number_to_currency @order.total_untaxed %></td>
      </tr>
      
      <tr>
        <td><%= t('invoice.shipment') %>: </td>
        <td><%= number_to_currency @order.ship_total %></td>
      </tr>
      
      <% @order.adjustments.promotion.each do |promotion| %>
        <tr>
          <td><%= promotion.label %> </td>
            <td><%= number_to_currency promotion.amount %> </td>
        </tr>
      <% end %>
      
      <% @order.adjustments.manual.each do |manual| %>
        <tr>
          <td><%= manual.label %> </td>
            <td><%= number_to_currency manual.amount %> </td>
        </tr>
      <% end %>
      
      <% @order.taxes.each do |tax| %>
        <tr>
          <td>
            <%= tax[:tax_rate].name%>
          </td>
          <td>
            <%= number_to_currency tax[:total_tax] %>
          </td>
        </tr>
      <% end%>

      <tr>
        <td><strong><%= t(:order_total) %>:</strong></td>
        <td><strong><span id='summary-order-total'><%= number_to_currency @order.total %></span></strong></td>
      </tr>
      
    </table>
    
  </body>
</html>
